<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
#doc
#	classname:	Home
#	scope:		PUBLIC
#	StartBBS起点轻量开源社区系统
#	author :doudou QQ:858292510 startbbs@126.com
#	Copyright (c) 2013 http://www.startbbs.com All rights reserved.
#/doc

class Teacher extends SB_Controller {

    function __construct() {
        parent::__construct();

        $this->load->library('myclass');

        $this->load->model('link_m');
        $this->load->model('teacher_m');
        $this->home_page_num = ($this->config->item('home_page_num')) ? $this->config->item('home_page_num') : 20;
    }

    /**
     * 文章详情
     */
    public function detail() {
//        <!--可能有附件-->
        //获取首页轮播图  或许首页信息 
        $id = intval($_GET['id']);

        $where = array(
            'id' => $id,
            'status' => 1
        );

        //获取列表
        $data['teacher'] = $this->teacher_m->getListByCondition("teacher", $where, array(), 0, 1);
        if (empty($data['teacher'])) {
            show_message('未找到该信息', site_url('teacher/index'));
        } else {
            $data['teacher'] = $data['teacher'][0];
        }
        $this->db->cache_on();
        $stats = $this->db->get('site_stats')->result_array();
        $data['stats'] = array_column($stats, 'value', 'item');
        $data['last_user'] = $this->db->select('username')->where('uid', @$data['stats']['last_uid'])->get('users')->row_array();
        $data['stats']['last_username'] = @$data['last_user']['username'];
        $this->db->cache_off();
//        var_dump($data);
//        die;
        //links
        $data['links'] = $this->link_m->get_latest_links();


        //action
        $data['action'] = 'detail';
        $this->load->view('teacher', $data);
    }

    /**
     * 列表 不想做分页   
     */
    public function index() {

        //获取首页轮播图  或许首页信息 
        //原始版本
        //获取列表
        $where = array('status ' => 1);
        $orderBy = array('o' => 'asc', 'id' => 'desc');
        $data['teacher_list'] = $this->teacher_m->getListByCondition('teacher', $where, $orderBy);
//        var_dump($data);
//        die;
        $this->db->cache_on();
        $stats = $this->db->get('site_stats')->result_array();
        $data['stats'] = array_column($stats, 'value', 'item');
        $data['last_user'] = $this->db->select('username')->where('uid', @$data['stats']['last_uid'])->get('users')->row_array();
        $data['stats']['last_username'] = @$data['last_user']['username'];
        $this->db->cache_off();

        //links
        $data['links'] = $this->link_m->get_latest_links();
        //action
        $data['action'] = 'index';
        $this->load->view('teacher', $data);
    }

    public function latest() {
        $data['list'] = $this->topic_m->get_topics_list_nopage(5);
        $this->load->view('latest', $data);
    }

    public function search() {
        $data['q'] = $this->input->get('q', TRUE);
        $data['title'] = '搜索';
        $this->load->view('search', $data);
    }

    public function getmore($page = 1) {
        //分页
        $page = intval($_GET['page']);
        $cateid = intval($_GET['cateid']);
        $limit = $this->home_page_num;
        $config['uri_segment'] = 3;
        $config['use_page_numbers'] = TRUE;
        $config['base_url'] = site_url('infoAry/getmore?page=' . $page);
        $config['total_rows'] = $this->info_art_m->count_infos($cateid);
        $config['per_page'] = $limit;
        $config['first_link'] = '首页';
        $config['last_link'] = '尾页';
        $config['num_links'] = 10;
//        var_dump($config);die;
        $this->load->library('pagination');
        $this->pagination->initialize($config);

        $start = ($page - 1) * $limit;
        $data['pagination'] = $this->pagination->create_links();
        //获取列表
        $data['info_list'] = $this->info_art_m->get_info_art_list($start, $limit, $cateid);
        //$data['category'] = $this->cate_m->get_category_by_node_id($node_id);
        $this->load->view('info_list_getmore', $data);
    }

}
